#include "ppstring.h"

namespace losor
{
	ppstring::ppstring( ppobject *parent ) :
		ppobject( "string", parent )
	{
		// TODO:
	}
	
	ppstring::~ppstring()
	{
		// TODO:
	}
	
	long ppstring::parser( code &_code )
	{
		int line = 0;
		unsigned char* ptr = code.str;

		if( *ptr == '\"' )
			++ptr;
		else if( ptr[0] == 'L' && ptr[1] == '\'' )
			ptr += 2;
		else
			return -1;
		while ( *ptr != '\"' && *ptr != '\n' && *ptr != 0 )
		{
			if( *ptr == '\\' )
			{
				++ptr;
				if( oct_num[*ptr] != 0 )
				{
					++ptr;
					if( oct_num[*ptr] != 0 )
						++ptr;
					if( oct_num[*ptr] != 0 )
						++ptr;
				}
				else if( *ptr == 'x' || *ptr == 'X' )
				{
					++ptr;
					if( hex_num[*ptr] != 0 )
						while( hex_num[*++ptr] != 0 ) ;
				}
				else
				{
					if( *ptr == '\n' )
						++line;
					++ptr;
				}
			}
			else
			{
				++ptr;
			}
		}
		if( *ptr == '\"' )
			++ptr;
		m_caption = string( _code.str, ptr - _code.str );
		m_line = _code.line + line;
		_code.str = ptr;
		_code.line += line;
	}
}

